# !/usr/bin/python3
# -*- coding:utf-8 -*-
"""
@author: JHC000abc@gmail.com
@file: tasks.py
@time: 2024/10/23 18:12 
@desc: 

"""

from app_celery import app_celery
from scripts import script_1, script_2, script_0, script_3, script_4, script_5
from cron.cron_clear import Solution
from cron.cron_monitor import Monitor
from sdk.utils.util_redis import Redis


@app_celery.task
def choose_function(data):
    """

    :param data:
    :return:
    """
    script_id = data.get("script_id", "0")
    func_map = {
        "0": script_0.Solution().process,
        "1": script_1.Solution().process,
        "2": script_2.Solution().process,
        "1556": script_3.Solution().process,
        "1473": script_4.Solution().process,
        "10": script_5.Solution().process,

    }
    # time.sleep(20)
    if script_id not in func_map.keys():
        script_id = "0"
    # 在调用方法里边捕获异常
    res = func_map.get(str(script_id))(data)
    return res


@app_celery.task
def clear():
    Solution().process()


@app_celery.task
def check_result():
    Monitor().process()


@app_celery.task
def check_token_redis():
    """
    检查并删除已过期的cookies
    :return:
    """
    Redis().check_token_redis()
